package com.yfp.system.api.factory;

import com.yfp.common.core.domain.R;
import com.yfp.system.api.RemoteBrowserLoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteBrowserLoginFallbackFactory implements FallbackFactory<RemoteBrowserLoginService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteBrowserLoginFallbackFactory.class);

    @Override
    public RemoteBrowserLoginService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteBrowserLoginService() {

            @Override
            public R<Integer> isFirstBrowserLogin(String token, String source) {
                return R.fail("获取浏览器是否首次使用失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> addBrowserLogin(String token, String source) {
                return R.fail("获取浏览器是否首次使用失败:" + throwable.getMessage());
            }
        };
    }
}
